﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Create.Master" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.Cinerarium>" %>

<%@ Import Namespace="Common" %>
<%@ Import Namespace="Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CurentPlace" runat="server">
    寄存位管理
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <input id="AreaGuid" style="display: none" />

    <div class="panel datagrid" style="width: auto;">
        <div class="panel-header">
            <div>
                选择寄存区域： 
                <select id="Area" name="Area">
                </select>
            </div>
        </div>
        <div class="panel-body" style="height: 100%;">
            <div style="padding: 10px">
                <div id="btnGroup">
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addpaihao()">新增排号</a>
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="editPai()">修改排</a>
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="editHao()">修改号</a>
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="dingjia()">修改价格</a>
                </div>
                <div class="bigdiv" style="display: none">
                </div>
                <div id="CinerariumStr">
                </div>

            </div>
        </div>

    </div>
    <div>
        <div id="dlgpaihao" class="easyui-dialog" title="新增排号" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        createdlgpaihao();
                    }
                },{
                    text:'取消',
                    handler:function(){
                        $('#dlgpaihao').dialog('close');
                    }
                }]
            ">

            <table>
                <tr>
                    <td>排名称:</td>
                    <td>
                        <input id="paihaopainame" class="textbox" type="text" name="paihaopainame" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td>排序号:</td>
                    <td>
                        <input id="paihaopaisort" class="easyui-numberbox" type="text" name="paihaopaisort" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td>开始号:</td>
                    <td>
                        <input id="paihaostartno" class="easyui-numberbox" type="text" name="paihaostartno" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td>结束号:</td>
                    <td>
                        <input id="paihaoendno" class=" easyui-numberbox" type="text" name="paihaoendno" data-options="required:true" />
                    </td>
                </tr>

                <tr>
                    <td>价格:</td>
                    <td>
                       <input id="paihaoprice" class=" easyui-numberbox" type="text" name="paihaoprice" data-options="required:true" />
                    </td>
                </tr>


            </table>

        </div>
        <div id="editPai" class="easyui-dialog" title="修改排" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        editpaisave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#editPai').dialog('close');
                    }
                }]
            ">
            <table>
                <tr>
                    <td>排名称:</td>
                    <td>
                        <select id="editpaipainame">
                        </select>
                    </td>
                </tr>


            </table>

        </div>
         <div id="editHao" class="easyui-dialog" title="修改号" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        edithaosave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#editHao').dialog('close');
                    }
                }]
            ">
            <table>
                <tr>
                    <td>号:</td>
                    <td>
                        <input id="haono" class=" easyui-numberbox" type="text" name="haono" data-options="required:true" />
                    </td>
                </tr>
            </table>
        </div>
        
        <div id="dingjia" class="easyui-dialog" title="定价" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        dingjiasave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#dingjia').dialog('close');
                    }
                }]
            ">
            <table>
                <tr>
                    <td>价格:</td>
                    <td>
                        <input id="dingjiaprice" class="easyui-numberbox" type="text" name="dingjiaprice" data-options="required:true" />
                    </td>
                </tr>


            </table>

        </div>
    </div>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
     <style>
        ul {
            clear: both;
        }

        li {
            float: left;
            list-style-type: none;
            width: 60px;
            text-align: center;
            height: 90px;
        }
    </style>
    <script type="text/javascript">

        $(function () {
            //初始化Area的选择项
            InitArea();
            $('#Area').change(function () {
                $('#AreaGuid').val($('#Area').val());
                GetCinerariumString();
            });

            $('#dlgpaihao').dialog("close");
            $('#editPai').dialog("close");
            $('#dingjia').dialog("close");
            $('#editHao').dialog("close");
            
        });



        function InitArea() {
            $('#Area').empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($('#Area'));
            var url = "../CinerariumArea/GetArea";
            $.ajax({
                url: url,
                type: "Post",

                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item["RowGuid"])
                            .text(item["Name"])
                            .appendTo($('#Area'));
                    });
                }
            });
        }
        function addpaihao() {
            var areaGuid = $('#AreaGuid').val();
            if (areaGuid == "") {
                alert("请选择寄存区域");
                return;
            }
            $('#dlgpaihao').dialog("open");
        }

        function createdlgpaihao() {
            var paihaopainame = $('#paihaopainame').val();
            var paihaopaisort = $('#paihaopaisort').val();
            var paihaostartno = $('#paihaostartno').val();
            var paihaoendno = $('#paihaoendno').val();
            var paihaoprice = $('#paihaoprice').val();
            if (paihaopainame == "") {
                alert("排名称不能为空");
                return;
            }
            if (paihaopaisort == "") {
                alert("排序号不能为空");
                return;
            }
            if (paihaostartno == "") {
                alert("开始号不能为空");
                return;
            }
            if (paihaoendno == "") {
                alert("结束号不能为空");
                return;
            }
            if (paihaoprice == "") {
                alert("价格不能为空");
                return;
            }

            $.ajax({
                url: "../Cinerarium/CreateCinerarium",
                type: "Post",
                data: { areaguid: $('#AreaGuid').val(), painame: paihaopainame, paisort: paihaopaisort, startno: paihaostartno, endno: paihaoendno, price: paihaoprice },
                dataType: "json",
                success: function (data) {

                    alert(data);
                    GetCinerariumString();
                    $('#dlgpaihao').dialog('close');
                }
            });
        }

        function GetCinerariumString() {
            $.ajax({
                url: "../Cinerarium/GetCinerariumString",
                type: "Post",
                data: { areaguid: $('#AreaGuid').val() },
                dataType: "json",
                success: function (data) {

                    $('#CinerariumStr').html(data);
                    $("input[ id^='Cinerarium'][type= 'checkbox']").change(function () {
                        var name = $(this).attr("name");
                        if ($(this).attr("checked")) {
                            $("input[name='" + name + "']").attr("checked", true);
                        } else {
                            $("input[name='" + name + "']").attr("checked", false);
                        }
                    });
                }
            });
        }

        function editpaisave() {
            var painame = $('#editpaipainame  option:selected').text();
            var paisort = $('#editpaipainame').val();


            var editpaipainame = $('#editpaipainame').val();
            if (editpaipainame == "") {
                alert("排名称不能为空");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            $.messager.confirm('操作提示', "确认修改这 " + count + " 项的排号吗？", function (r) {
                if (r) {
                    $.post("../Cinerarium/EditPai", { query: arr.join(","), painame: painame, paisort: paisort, areaguid: $('#AreaGuid').val() }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据
                            $.messager.alert('操作提示', '修改排号成功!', 'info');
                            $('#editPai').dialog('close');
                            GetCinerariumString();
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '修改排号失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');

                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');

                            }
                        }
                    });
                }
            });


        }

        function editPai() {
            var areaguid = $('#AreaGuid').val();
            if (areaguid == "") {
                alert("请选择寄存区域");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            if (count < 1) {
                alert("请至少选择一项。");
                return;
            }

            $('#editpaipainame').empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($('#editpaipainame'));
            var url = "../Cinerarium/GetPai";
            $.ajax({
                url: url,
                type: "Post",
                data: { areaguid: areaguid },
                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item.Pai)
                            .text(item.PaiName)
                            .appendTo($('#editpaipainame'));
                    });
                }
            });

            $('#editPai').dialog('open');
        }

        function edithaosave() {
            var editHao = $('#haono').val();
            if (editHao == "") {
                alert("号不能为空");
                return;
            }
            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }
            });
            $.messager.confirm('操作提示', "确认修改这 " + count + " 项的号吗？", function (r) {
                if (r) {
                    $.post("../Cinerarium/EditHao", { query: arr.join(","), edithao: editHao }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据
                            $.messager.alert('操作提示', '修改号成功!', 'info');
                            $('#editHao').dialog('close');
                            GetCinerariumString();
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '修改号失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');

                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');

                            }
                        }
                    });
                }
            });
        }

        function editHao() {
            var areaguid = $('#AreaGuid').val();
            if (areaguid == "") {
                alert("请选择寄存区域");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            if (count < 1) {
                alert("请至少选择一项。");
                return;
            }

            $('#editHao').dialog('open');
        }

        function dingjiasave() {
            var price = $('#dingjiaprice').val();
            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }
            });
            $.messager.confirm('操作提示', "确认设置这 " + count + " 项墓位的价格吗？", function (r) {
                if (r) {
                    $.post("../Cinerarium/AjaxDingJia", { query: arr.join(","), price: price }, function (res) {
                        if (res == "OK") {

                            $.messager.alert('操作提示', '设置成功!', 'info');
                            $('#dingjia').dialog('close');
                            GetCinerariumString();
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '设置失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');

                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');

                            }
                        }
                    });
                }
            });
        }
        function dingjia() {
            var quguid = $('#AreaGuid').val();
            if (quguid == "") {
                alert("请选择寄存区域");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            if (count < 1) {
                alert("请至少选择一项。");
                return;
            }

            $('#dingjia').dialog('open');
        }
    </script>
</asp:Content>

